#include"comm.h"
#include<unistd.h>
#include<sys/shm.h>
#include<sys/types.h>
int main()
{
  key_t k=ftok(PATHNAME,PROJ_ID);
  if(k<0)
  {
    printf("frok error!\n");
    return 1;
  }
  printf("%x\n",k);
  int shmid=shmget(k,size,IPC_CREAT|IPC_EXCL|0666);
  if(shmid<0)
  {
    perror("shmget");
    return 2;
  }
  printf("shimid:%d\n",shmid);
  printf("attach begin\n");
  sleep(5);
  char*mem=shmat(shmid,NULL,0);

int i=0;
  while(1)
  {
    mem[i]='A'+i;
    sleep(1);
    i++;
    mem[i]='\0';
  }
  printf("attch end!,%d\n",(int)mem);
  shmdt(mem);
  sleep(5);
  
  
  shmdt(mem);//取消关联
  shmctl(shmid,IPC_RMID,NULL);//删除共享内存
  return 0;
}
